package net.caixiaomi.info.shopkeeper.adapter;

import android.text.TextUtils;

import net.caixiaomi.info.R;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.model.OrderInfoItem;
import net.caixiaomi.info.model.OrderInfoModel;
import net.caixiaomi.info.model.PrintTicketItem;
import net.caixiaomi.info.util.Constants;

import java.util.List;

/**
 * Created by mac on 2018/11/19.
 */

public class ShopDetailAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ShopDetailAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(Constants.ITEM_MATCH_LIVE0, R.layout.shop_order_top_layout);
        addItemType(Constants.ITEM_MATCH_LIVE1, R.layout.shop_order_item0_layoutt);
        addItemType(Constants.ITEM_MATCH_LIVE2, R.layout.shop_order_mid_layout);
        addItemType(Constants.ITEM_MATCH_LIVE3, R.layout.shop_order_item1_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (item.getItemType()) {
            case Constants.ITEM_MATCH_LIVE1:
                bindItem0(helper, item);
                break;
            case Constants.ITEM_MATCH_LIVE2:
                bindItemMid(helper, item);
                break;
            case Constants.ITEM_MATCH_LIVE3:
                bindItem1(helper, item);
                break;

        }
    }

    private void bindItem0(BaseViewHolder helper, MultiItemEntity item) {
        try {
            OrderInfoItem entity= (OrderInfoItem) item;
            helper.setText(R.id.shop_detail_lv0, entity.getChangci());
            String match=entity.getMatch();
            String[] ms=match.split("VS");
            helper.setText(R.id.shop_detail_lv1, ms[0]);
            helper.setText(R.id.shop_detail_lv2, ms[1]);
            helper.setGone(R.id.flag, TextUtils.equals(entity.getIsDan(), "1"));
            String content="";
            for(int i=0;i<entity.getCathecticResults().size();i++){
                if(i!=0&&i!=entity.getCathecticResults().size()-1){
                    content=content+"\n";
                }
                OrderInfoItem.CathecticResultsBean bean=entity.getCathecticResults().get(i);
                content=content+bean.getPlayType()+": ";
                for(int j=0;j<bean.getCathectics().size();j++){
                    content=content+bean.getCathectics().get(j).getCathectic()+" ";
                }
            }
            helper.setText(R.id.shop_detail_lv3, content);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void bindItem1(BaseViewHolder helper, MultiItemEntity item) {
        try {
            PrintTicketItem entity= (PrintTicketItem) item;
            String content=entity.getTickeContent();
            content=content.replaceAll("X","X\n");
            helper.setText(R.id.name, content);
            helper.setText(R.id.way, entity.getPassType());
            helper.setText(R.id.treble, entity.getMultiple()+"倍");
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
    private void bindItemMid(BaseViewHolder helper, MultiItemEntity item) {
        try {
            OrderInfoModel entity= (OrderInfoModel) item;
            helper.setText(R.id.shop_detail_tv0, entity.getPassType());
            helper.setText(R.id.shop_detail_tv1, entity.getCathectic()+"倍");
            helper.setText(R.id.shop_detail_tv2, "下单时间: "+entity.getCreateTime());
            helper.setText(R.id.shop_detail_tv3, "共"+entity.getMoneyPaid()+"元");
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
